package genercis;

public class User {

    private String username;
    private Integer age;
    private Double height;

    public User(String username, Integer age, Double height) {
        this.username = username;
        this.age = age;
        this.height = height;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getHeight() {
        return height;
    }

    public void setHeight(Double height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }

    public static void main(String[] args) {
        User user1 = new User("小王",12,153.4);
        User user2 = new User("小李",14,163.4);
        User user3 = new User("小张",13,123.4);
        User user4 = new User("小杨",4,6.4);

        User[] users = {user1,user2,user3,user4};
        for (int i = 0; i < users.length-1; i++) {
            for (int j = 0; j < users.length - i - 1; j++) {
                if(users[j].age > users[j+1].age){
                    User temp = users[j];
                    users[j] = users[j+1];
                    users[j+1] = temp;
                }
            }
        }
        for (int i = 0; i < users.length; i++) {
            System.out.println(users[i]);
        }
    }
}
